#!/bin/bash
work_dir="/opt/soft/myonlineddl"                                  #工作目录
. ${work_dir}/function/log/f_logging.sh
if [ -f "${work_dir}/conf/myonlineddl.conf" ]
then
    . ${work_dir}/conf/myonlineddl.conf
fi

log_addr='${BASH_SOURCE}:${FUNCNAME}:${LINENO}' #eval echo ${log_addr}

mysql_comm_dbadb="mysql --default-character-set=utf8 -u${mysql_user} -p${mysql_pass} -h${dbadb_host} -P${dbadb_port} ${dbadb_db}"
hook_tmp="${work_dir}/hook/tmp"

function f_main()
{
    mkdir -p ${hook_tmp}
    log_addr='${BASH_SOURCE}:${FUNCNAME}:${LINENO}' #eval echo ${log_addr}
    
    f_logging "$(eval echo ${log_addr}):ERROR" "库表: ${GH_OST_DATABASE_NAME}.${GH_OST_TABLE_NAME} 原表预计总行数: ${GH_OST_ESTIMATED_ROWS}, 实际拷贝总行数: ${GH_OST_COPIED_ROWS}"
    
    if [[ $(cat ${hook_tmp}/${GH_OST_DATABASE_NAME}.${GH_OST_TABLE_NAME}.txt) -gt ${GH_OST_COPIED_ROWS} ]]
    then
       f_logging "$(eval echo ${log_addr}):ERROR" "拷贝总行数不匹配, 本次修改失败, 即将退出改表任务."
       sleep 5
       rm -f ${hook_tmp}/${GH_OST_DATABASE_NAME}.${GH_OST_TABLE_NAME}.txt
       f_logging "$(eval echo ${log_addr}):WARN" "删除临时文件 ${hook_tmp}/${GH_OST_DATABASE_NAME}.${GH_OST_TABLE_NAME}.txt"
       exit -1
    fi
    f_logging "$(eval echo ${log_addr}):INFO" "拷贝总行数匹配"
    f_logging "$(eval echo ${log_addr}):WARN" "删除临时文件 ${hook_tmp}/${GH_OST_DATABASE_NAME}.${GH_OST_TABLE_NAME}.txt"
}

f_main
